#include<iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

int main()
{
    int sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    if(sockfd<0)
    {
        perror("socket error");
        return -1;
    }
    struct sockaddr_in addr;
    addr.sin_family=AF_INET;
    addr.sin_port=htons(9090);
    addr.sin_addr.s_addr=inet_addr("0.0.0.0");
    socklen_t len=sizeof(addr);
    if(bind(sockfd,(struct sockaddr*)&addr,len)<0)
    {
        perror("bind error");
        return -1;
    }
    listen(sockfd,5);
    while(1)
    {
        int newfd=accept(sockfd,(struct sockaddr*)&addr,&len);
        if(newfd<0)
        {
            continue;
        }
        char tmp[4096]={0};
        recv(newfd,tmp,4095,0);
        printf("%s\n",tmp);
        close(newfd);
    }
    close(sockfd);
    return 0;
}